package tomoto.assertion;

/**
 * Utility to check the parameters and throw appropriate exceptions like
 * {@link IllegalArgumentException}.
 */
public class ParamUtil {
	@Deprecated
	private ParamUtil() {}

	/**
	 * Checks the condition and throws {@link IllegalArgumentException} if it is
	 * not satisfied.
	 * 
	 * @param condition condition to check
	 * @throws IllegalArgumentException condition is false
	 */
	public static void check(boolean condition) {
		if (!condition) {
			throw new IllegalArgumentException();
		}
	}

	/**
	 * Throws {@link IllegalArgumentException}. This function is declared to
	 * return an exception so that you can write throws statement like the
	 * following example to avoid compile errors related to unreachable code.
	 * 
	 * <pre>
	 * public void f(int param) {
	 *   switch (param) {
	 *   case 0:
	 *     ...
	 *     return ...;
	 *   case 1:
	 *     ...
	 *     return ...;
	 *   ...
	 *   default:
	 *     <b>throw</b> ParamUtil.fail(); // invalid parameter is given
	 *   }
	 * }
	 * // compiler now knows this code is never reached here.
	 * </pre>
	 * 
	 * @return This function never returns but always throws an exception.
	 * @throws IllegalArgumentException thrown always
	 */
	public static IllegalArgumentException fail() {
		throw new IllegalArgumentException();
	}
}
